# SETTINGS
#NuGet
$fileName = "Globsite.Globalization.Mvc.dll"
$sourceFolder = "..\Mvc\bin\NuGet-net45\"
$targetFolder = ".\lib\net45\"
$nuGetPath = "..\Solution Items\Tools\NuGet\NuGet.exe"
#MSBuild
$solutionFile = "..\Globsite.Globalization.sln"
$projectName = "Mvc"
$projectConfiguration = "NuGet-net45"
$msBuildPath = "..\Solution Items\Tools\MSBuild\MSBuild.exe"


# Build the source project.
Write-Host "`r`n***** Building... *****`r`n" -ForegroundColor Yellow
Try
{
    Start-Process -FilePath $msBuildPath -ArgumentList "$($solutionFile) /target:$($projectName) /property:Configuration=""$($projectConfiguration)"" /verbosity:normal" -Wait
}
Catch
{
    Write-Host "***** Building failed *****" -ForegroundColor Red
    Write-Host "`r`n***** Press Enter to exit *****" -ForegroundColor Yellow
    Read-Host
    Break
}

# Copy the assembly file from a source project. Replace old one if exists.
Write-Host "`r`n***** Copying assembly... *****" -ForegroundColor Yellow
Try
{
	Copy-Item -Path "$($sourceFolder)$($fileName)" -Destination $targetFolder -Force
}
Catch
{
	Write-Host "***** Copying failed *****" -ForegroundColor Red
    Write-Host "`r`n***** Press Enter to exit *****" -ForegroundColor Yellow
    Read-Host
    Break
}

# Create NuGet package with the package version consistent with the assembly version.
Write-Host "`r`n***** Packing... *****`r`n" -ForegroundColor Yellow
Try
{
	$assemblyVersion = [Reflection.AssemblyName]::GetAssemblyName("$($targetFolder)$($fileName)").Version.ToString()
	Start-Process -FilePath $nuGetPath -ArgumentList "pack -IncludeReferencedProjects -Version $($assemblyVersion) -Verbosity detailed" -NoNewWindow -Wait
}
Catch
{
	Write-Host "***** Packing failed *****" -ForegroundColor Red
    Write-Host "`r`n***** Press Enter to exit *****" -ForegroundColor Yellow
    Read-Host
    Break
}

# Prevent for closing the window.
Write-Host "`r`n***** Press Enter to exit *****" -ForegroundColor Yellow
Read-Host